/**
 * com.chaeron.GPS - An API for access to GPS devices.
 *
 *
 * Copyright (c) 2001, 2002 Chaeron Corporation,
 * All rights reserved.
 * 
 * Chaeron grants you a non-exclusive license to use, modify and re-distribute
 * this program under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version, provided that this copyright notice and 
 * license appear on all copies of the software.
 * 
 * Software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR
 * IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
 * HEREBY EXCLUDED. THE ENTIRE RISK ARISING OUT OF USING THE SOFTWARE IS ASSUMED
 * BY THE LICENSEE. See the GNU General Public License for more details.
 *
 * CHAERON AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
 * LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR DISTRIBUTING SOFTWARE.
 * IN NO EVENT WILL CHAERON OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
 * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL
 * OR PUNITIVE DAMAGES, HOWEVER CAUSED AN REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF CHAERON HAS
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 * @version     1.02
 * @author      Andrzej Jan Taramina, Chaeron Corporation
 *              andrzej@chaeron.com
 */

package com.chaeron.GPS;

//***************************************************************************
//*
//*     Imports
//*
//***************************************************************************/

import java.util.*;

//***************************************************************************
//*
//*     Degrees class definition
//*
//***************************************************************************/

/**
 * The Degrees class defines lat/long in degrees and seconds notation
 *
 */

public class Degrees
{
	
	//***************************************************************************
	//*
	//*     Constants
	//*
	//***************************************************************************/
	
	private static final char			minChar		= '"';
	private static final char			secChar		= '\'';
	
	
	//***************************************************************************
	//*
	//*     Attributes
	//*
	//***************************************************************************/
	
	int			minutes			= 0;
	double		seconds			= 0.0d;
	double		degrees			= 0.0d;
	String		direction		= "";
	boolean		negative		= false;
	
	
	//***************************************************************************
	//*
	//*     Constructors
	//*
	//***************************************************************************/
	
	
	/**
	 * Construct a postition from minutes/seconds.  Minutes and seconds should normally
	 * be of the same sign (ie. both +ve or both -ve).
	 *
	 * @param		minutes		
	 * @param		seconds
	 *
	 */
	
	public Degrees( int minutes, double seconds )
	{
		this.minutes = minutes;
		this.seconds = seconds;
		
		degrees = (double)minutes + ( seconds / 60.0d );
		
		if( seconds < 0.0f ) {
			seconds *= -1.0d;
		}
		
		if( minutes < 0 ) {
			minutes *= -1;
			negative = true;
		}
	}
	
	
	/**
	 * Construct a postition from decimal degrees
	 *
	 * @param		degrees		
	 *
	 */
	
	public Degrees( double degrees )
	{
		this.degrees = degrees;
		
		minutes	= (int)degrees;
		seconds = ( degrees - (double)minutes ) * 60;
		
		if( seconds < 0.0d ) {
			seconds *= -1.0d;
		}
		
		if( minutes < 0 ) {
			minutes *= -1;
			negative = true;
		}
	}
	
	
	//***************************************************************************
	//*
	//*     Accessor Methods
	//*
	//***************************************************************************/
	
	
	/**
	 * Get Direction
	 *
	 * @return				direction (false = negative values for minutes/seconds)
	 */
	
	private boolean getDirection()
	{
		return( negative );
	}
	
	
	/**
	 * Get Direction String
	 *
	 * @return				direction string (N/S/E/W)
	 */
	
	private String getDirectionString()
	{
		return( direction );
	}
	
	
	/**
	 * Set Direction
	 *
	 */
	
	protected void setDirectionString( String pos, String neg )
	{
		if( degrees < 0.0d ) {
			direction = neg;
		} else if( degrees > 0.0d ) {
			direction = pos;
		}
	}
	
	
	/**
	 * Get Minutes. This value is always positive.  getDirection() to test for negative value
	 *
	 * @return				minutes
	 */
	
	public int getMinutes()
	{
		return( minutes );
	}
	
	
	/**
	 * Get Seconds. This value is always positive.  getDirection() to test for negative value
	 *
	 * @return				Seconds
	 */
	
	public double getSeconds()
	{
		return( seconds );
	}
	
	
	/**
	 * Convert Degrees/Seconds to Decimal Degrees
	 *
	 * @return				Degress as decimal
	 */
	
	public double getDegrees()
	{
		return( degrees );
	}
	
	
	/**
	 * Return Position value as a string
	 *
	 * @return				Minutes/Seconds as string
	 */
	
	public String toString()
	{
		return( direction + " " + minutes + minChar + " " + seconds + secChar );
	}
	
	
	
}
